package io.lckgroup.modules.lck.controller.wxgzh;

import io.lckgroup.common.utils.R;
import io.lckgroup.modules.lck.annotation.WxLogin;
import io.lckgroup.modules.lck.entity.OrderMainEntity;
import io.lckgroup.modules.lck.service.WxgzhPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mp/wxgzhPay")
public class WxgzhPayConttroller {

    @Autowired
    private WxgzhPayService wxgzhPayService;

    /**
     * 微信支付
     *
     * @param merchantId
     * @param orderNum
     * @return
     */
    @GetMapping("/wxPay")
    @WxLogin
    public R wxPay(@RequestParam Long merchantId, @RequestParam String orderNum) {
        String url = wxgzhPayService.getPayUrl(merchantId, orderNum);
        return R.ok().put("url", url);
    }

    /**
     * 微信重新支付
     *
     * @param merchantId
     * @param orderNum
     * @return
     */
    @GetMapping("/rePayWeixin")
    @WxLogin
    public R rePayWeixin(@RequestParam Long merchantId, @RequestParam String orderNum) {
        OrderMainEntity orderMainEntity = wxgzhPayService.updateOrderNum(merchantId, orderNum);
        String url = wxgzhPayService.getPayUrl(orderMainEntity.getMerchantId(), orderMainEntity.getOrderId());
        return R.ok().put("url", url);
    }

}
